package logic

import (
	"context"
	"home-furnish/homerpc/homerpc"
	"home-furnish/homerpc/internal/svc"
	"home-furnish/models/mysql"

	"github.com/zeromicro/go-zero/core/logx"
)

type HomeShowLogic struct {
	ctx    context.Context
	svcCtx *svc.ServiceContext
	logx.Logger
}

func NewHomeShowLogic(ctx context.Context, svcCtx *svc.ServiceContext) *HomeShowLogic {
	return &HomeShowLogic{
		ctx:    ctx,
		svcCtx: svcCtx,
		Logger: logx.WithContext(ctx),
	}
}

// 详情
func (l *HomeShowLogic) HomeShow(in *homerpc.HomeShowRequest) (*homerpc.HomeShowResponse, error) {
	// todo: add your logic here and delete this line

	var home mysql.Home

	if err := home.HomeShow(mysql.DB, in.HomeId); err != nil {
		return nil, err
	}
	var class mysql.Class

	if err := class.ClassShow(mysql.DB, home.ClassId); err != nil {
		return nil, err
	}
	var brand mysql.Brand
	if err := brand.BrandShow(mysql.DB, home.BrandId); err != nil {
		return nil, err
	}
	return &homerpc.HomeShowResponse{
		HomeId:    in.HomeId,
		Name:      home.Name,
		Image:     home.Image,
		Price:     float32(home.Price),
		ClassName: class.Name,
		BrandName: brand.Name,
	}, nil
}
